package com.mostromas.ess.project.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mostromas.ess.entities.PDDProduct;
import com.mostromas.ess.project.mapper.PDDProductMapper;
import com.mostromas.ess.project.req.PDDProductREQ;
import com.mostromas.ess.project.service.IPDDProductService;
import com.mostromas.ess.util.base.Result;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class PDDProductServiceImpl extends ServiceImpl<PDDProductMapper, PDDProduct> implements IPDDProductService {
    @Override
    public Result queryList(PDDProductREQ req) {
        QueryWrapper<PDDProduct> wrapper = new QueryWrapper<>();
        if(req.getGoodsName()!=null){
            wrapper.like("goods_name",req.getGoodsName());
        }
        return Result.ok(baseMapper.selectPage(req.getPage(),wrapper));
    }
    @Transactional
    @Override
    public Result saveList(List<PDDProduct> list) {
        boolean state = this.saveOrUpdateBatch(list);
        return state?Result.ok():Result.error("插入错误");
    }
}
